package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.Callback;
import com.ruoyi.system.domain.Callback;
import com.ruoyi.system.service.ICallbackService;
import com.ruoyi.system.service.ICallbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 反馈回复Controller
 *
 * @author CJJ
 * @date 2024-06-27
 */
@RestController
@RequestMapping("/callback")
public class CallBackController extends BaseController{
        @Autowired
        private ICallbackService callbackService;

        /**
         * 查询对应用户id反馈信息列表
         */
        @GetMapping("/myList/{userName}")
        public TableDataInfo myList(@PathVariable("userName") String userName)
        {
            startPage();
            List<Callback> list = callbackService.selectMyCallbackList(userName);
            return getDataTable(list);
        }

        /**
         * 查询所有反馈信息列表
         */
        @GetMapping("/allList")
        public TableDataInfo allList(Callback callback)
        {
            startPage();
            List<Callback> list = callbackService.selectAllCallbackList(callback);
            return getDataTable(list);
        }

        /**
         * 获取反馈信息详细信息
         */
        @GetMapping(value = "/{callbackId}")
        public AjaxResult getInfo(@PathVariable("callbackId") Integer callbackId)
        {
            return success(callbackService.selectCallbackByCallbackId(callbackId));
        }

        /**
         * 新增反馈信息
         */
        @Log(title = "反馈信息", businessType = BusinessType.INSERT)
        @PostMapping
        public AjaxResult add(@RequestBody Callback callback)
        {
            return toAjax(callbackService.insertCallback(callback));
        }

        /**
         * 修改反馈信息
         */
        @Log(title = "反馈信息", businessType = BusinessType.UPDATE)
        @PutMapping
        public AjaxResult edit(@RequestBody Callback callback)
        {
            return toAjax(callbackService.updateCallback(callback));
        }

        /**
         * 删除反馈信息
         */
        @Log(title = "反馈信息", businessType = BusinessType.DELETE)
        @DeleteMapping("/{callbackIds}")
        public AjaxResult remove(@PathVariable Integer[] callbackIds)
        {
            return toAjax(callbackService.deleteCallbackByCallbackIds(callbackIds));
        }
}
